package com.ddd.infrastructure.utils;

import com.ddd.infrastructure.common.Result;
import com.ddd.infrastructure.durable.ResultEnum;

/**
 * @author
 */
public class ResultUtil {
    private ResultUtil() { }

    // 返回成功
    public static <T> Result<T> success() {
        Result<T> result = new Result<>();
        result.setCode(ResultEnum.SUCCESS.getCode());
        return result;
    }
    // 返回成功的数据返回
    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setCode(ResultEnum.SUCCESS.getCode()).setData(data);
        return result;
    }



    // 返回成功的指定消息
    public static <T> Result<T> success(String msg) {
        Result<T> result = new Result<>();
        result.setCode(ResultEnum.SUCCESS.getCode()).setMsg(msg);
        return result;
    }

    // 返回成功 状态码,数据返回
    public static <T> Result<T> success(String code, T data) {
        Result<T> result = new Result<>();
        return result.setCode(code).setData(data);
    }
    // 返回成功 状态码,消息 , 错误的数据
    public static <T> Result<T> success(String code, T data, String msg) {
        Result<T> result = new Result<>();
        return result.setCode(code).setData(data).setMsg(msg);
    }


    // 返回错误
    public static <T> Result<T> fail() {
        Result<T> result = new Result<>();
        result.setCode(ResultEnum.FAIL.getCode());
        return result;
    }


    // 返回错误的消息提示
    public static <T> Result<T> fail(String msg) {
        Result<T> result = new Result<>();
        result.setCode(ResultEnum.FAIL.getCode()).setMsg(msg);
        return result;
    }

    // 返回错误的数据
    public static <T> Result<T> fail(T data) {
        Result<T> result = new Result<>();
        result.setCode(ResultEnum.FAIL.getCode()).setData(data);
        return result;
    }

    // 返回错误状态码和消息
    public static <T> Result<T> fail(String code, String msg){
        Result<T> result = new Result<>();
        result.setCode(code).setMsg(msg);
        return result;
    }

    /**
     *  返回错误的 状态码 ,消息 , 错误的数据
     */
    public static <T> Result<T> fail(String code, String msg, T data){
        Result<T> result = new Result<>();
        result.setCode(code).setMsg(msg).setData(data);
        return result;
    }
}
